<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8" />
    <title>激活码生成</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <link href="http://tv.speechb.com/lib/layui/css/layui.css" rel="stylesheet"/>
</head>
<body >
<!--
<script id="editor" type="text/plain" style="height: 150px;"/>

-->
<!-- Main content -->
<div style="margin-top: 30px;margin-right: 22px">
            <div class="layui-form" action="" style="max-width: 640px;margin: 0 auto">
                <div class="layui-form-item">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">激活码</label>
                        <div class="layui-input-block">
                            <textarea rows="10" id="activation_code" name="desc" style="width:100%;max-height: 220px;overflow:auto;" class="layui-textarea" readonly></textarea>
                            <br/>
                            <a id="copy_code" style="margin-top: 6px;color: #0000EE">复制激活码</a>
                        </div>
                    </div>

                    <label class="layui-form-label">时长选择</label>
                    <div class="layui-input-block">
                        <select name="mouthCount" lay-verify="required">
                            <option  value=""></option>
                            <option value="1">月卡（一个月）</option>
                            <option value="3">季卡（三个月）</option>
                            <option value="12">年卡（12个月）</option>
                            <option value="2400"> 永久（200年）</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">数量</label>
                    <div class="layui-input-inline">
                        <input type="number" name="codeCount" required lay-verify="required" placeholder="请输入生成激活码个数" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">即拿即用</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="status" title="已占">
                    </div>
                </div>

                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-input-block">
                        <button id="submitBtn" class="layui-btn" lay-submit lay-filter="formDemo" style="margin: 0 auto">立即提交</button>
                    </div>
                </div>
            </div>

<!--    <canvas id="catw" width="500" height="500" style="position: fixed; bottom: 0;right:0;"></canvas>
    <script src=" https://cdn.zhangxinxu.com/sp/demo/live2d/live2d/js/live2d.js"></script>
    <script type="text/javascript">
        loadlive2d("catw", " https://cdn.jsdelivr.net/gh/QiShaoXuan/live2DModel@1.0.0/live2d-widget-model-tororo/assets/tororo.model.json");
    </script>-->
</div>
<script type="text/javascript" charset="utf-8" src="http://tv.speechb.com/lib/layui/layui.js"></script>
<script src="http://tv.speechb.com/lib/superui/content/ui/global/jQuery/jquery.min.js"></script>
<script type="text/javascript">

    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                type : "GET",
                url : "/admin/vip_activation_code/code",
                data: {
                    "month_count": data.field.mouthCount,
                    "code_count": data.field.codeCount,
                    "status":data.field.status=="on"?"2":"1"
                },
                success : function(result) {
                    $("#activation_code").html("");
                    var activationCode = $("#activation_code");
                    if(result.code==1) {
                        for(var i=0;i<result.data.length;i++ ) {
                            if(i!=0) {
                                activationCode.append("&#10;");
                            }
                            activationCode.append(result.data[i]);
                        }
                    } else {
                        layer.msg('生成失败了！', {icon: 5});
                    }
                },
                error : function(e){
                    layer.msg('请求异常！', {icon: 5});
                }
            });
            return false;
        });
    });
    $(function(){

        $("#copy_code").click(function () {
            var copyText = $("#activation_code");//获取对象
            copyText .select();//选择
            document.execCommand("Copy");//执行复制

            layer.msg('复制成功', {icon: 1});
        });
    });

</script>
</body>

</html>